/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.veles.infowindow;

import javax.faces.application.ResourceDependencies;
import javax.faces.application.ResourceDependency;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.render.Renderer;

/**
 * Renderer Base of info window
 * @author Jan Ferko
 */
@ResourceDependencies({
    @ResourceDependency(name="infowindow.js", target="head")
})
public class InfoWindowRendererBase extends Renderer{
    
    /**
     * 
     * @param component component which is rendered
     * @return key of parent map server
     */
    public String getMapServerType(UIComponent component){
        if(component == null || !(component instanceof AbstractInfoWindow)){
            return null;
        }
        final AbstractInfoWindow window = (AbstractInfoWindow) component;
        return window.resolveMapServer().getId();
    }
    
    /**
     * Method check if component has setted latitude attribute
     * @param component component, which we want to control
     * @return true if latitude is setted
     */
    public boolean hasLatitude(UIComponent component){
        if(component == null || !(component instanceof AbstractInfoWindow)){
            return Boolean.FALSE;
        }
        final AbstractInfoWindow window = (AbstractInfoWindow) component;
        return window.getLatitude() != null;
    }
    
    /**
     * Method check if component has setted longitude attribute
     * @param component component, which we want to check
     * @return if longitude is setted and component is {@link AbstractInfoWindow} instance
     */
    public boolean hasLongitude(UIComponent component){
        if(component == null || !(component instanceof AbstractInfoWindow)){
            return Boolean.FALSE;
        }
        final AbstractInfoWindow window = (AbstractInfoWindow) component;
        return window.getLongitude() != null;
    }            
}
